home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Text / Textension / Include / TextensionCommand.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  7.1 KB  |  285 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TextensionCommand.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Essam Zaky
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>      1/4/94    EZ        clean up
  13.          <1>      1/4/94    EZ        first checked in
  14.  
  15. */
  16.  
  17. #ifndef _TextensionCommand_
  18. #define _TextensionCommand_
  19.  
  20. #ifndef _Textension_
  21. #include "Textension.h"
  22. #endif
  23.  
  24. #ifndef _TSMTextension_
  25. #include "TSMTextension.h"
  26. #endif
  27.  
  28. #ifndef _Frames_
  29. #include "Frames.h"
  30. #endif
  31.  
  32. #ifndef _TextensionIOSuite_
  33. #include "TextensionIOSuite.h"
  34. #endif
  35.  
  36. #ifndef _Streams_
  37. #include "Streams.h"
  38. #endif
  39.  
  40. #ifndef _AttrObject_
  41. #include "AttrObject.h"
  42. #endif
  43.  
  44. #ifdef txtnRulers
  45. #ifndef _RulerObject_
  46. #include "RulerObject.h"
  47. #endif
  48. #endif
  49.  
  50. //**************************************************************************************************
  51.  
  52.  
  53. //constants for command state (returned from "GetCommandState")
  54. const char kDoCommandState = 0;
  55. const char kUndoCommandState = 1;
  56. const char kRedoCommandState = 2;
  57.  
  58. const char kErrorCommandState = 4;
  59.  
  60. //**************************************************************************************************
  61.  
  62. const short kNoTextensionCommand = 0;
  63. //initializes the variables to nil, so that a Free will not release theme
  64.  
  65. //••constants for CTextensionEditCommand command ids
  66.  
  67. const short kTextensionKeyCommand = 1;
  68. const short kTextensionCutCommand = 1 << 1;
  69. const short kTextensionPasteCommand = 1 << 2;
  70. const short kTextensionClearCommand = 1 << 3;
  71.  
  72.  
  73. const short kTextensionRunCommand = 1 << 4; //face, font, color, ...
  74.  
  75. #ifdef txtnRulers
  76. const short kTextensionRulerCommand = 1 << 5; //add tab, delete tab, just, line spacing, ...
  77. #endif
  78.  
  79. #ifdef txtnAdvRulers
  80. const short kTextensionPasteRulerCommand = 1 << 6;
  81. const short kTextensionModifyTabCommand = 1 << 7;
  82. #endif
  83.  
  84. const short kTextensionTextModifCommandMask = kTextensionKeyCommand + kTextensionCutCommand + kTextensionPasteCommand + kTextensionClearCommand;
  85. const short kTextensionRunsModifCommandMask = kTextensionRunCommand;
  86.  
  87. #ifdef txtnRulers
  88. #ifdef txtnAdvRulers
  89. const short kTextensionRulersModifCommandMask = kTextensionRulerCommand+kTextensionPasteRulerCommand+kTextensionModifyTabCommand;
  90. #else
  91. const short kTextensionRulersModifCommandMask = kTextensionRulerCommand;
  92. #endif
  93. #endif
  94.  
  95. //•descendents should not use command numbers 1..5000
  96.  
  97.  
  98. //*************************************************************************************************
  99.  
  100.  
  101. #ifdef txtnAdvRulers
  102. /*when calling ITextensionEditCommand, the modifier.fAttr should be kTabAttr, fAttrValue should 
  103. point to a "TModifyTabCommandData" struct, fMessage is not used */
  104.  
  105. struct TModifyTabCommandData {
  106.     short oldValue;
  107.     Ttab newTab;
  108. };
  109. typedef TModifyTabCommandData* TModifyTabCommandDataPtr;
  110. #endif
  111.  
  112. //**************************************************************************************************
  113.  
  114. //•"KeyCommandResult" defs
  115. typedef unsigned char KeyCommandResult;
  116.  
  117. const KeyCommandResult kSameKeyCommand = 0;
  118. const KeyCommandResult kEndKeyCommand = 1 << 0;
  119. const KeyCommandResult kStartNewKeyCommand = 1 << 1;
  120.  
  121. //**************************************************************************************************
  122.  
  123. class CTextensionCommand : public HandleObject {
  124. public:
  125. //-----
  126.     CTextensionCommand();
  127.     
  128.     virtual void Free();
  129.  
  130.     OSErr Execute(short* userAction = nil);
  131.     //userAction has the same meaning as the value returned from CTextension::DisplayChanged
  132.  
  133.     inline short GetCommandId() const {return fCmdId;}
  134.     inline char GetCommandState() const {return fState;}
  135.     
  136.     inline char CanUndo() {return fCanUndo;}
  137.     
  138.     inline CTextension* GetTextension() const {return fTextension;}
  139.     
  140. protected:
  141. //--------
  142.     CTextension* fTextension;
  143.  
  144.     short fCmdId;
  145.     
  146.     char fCanUndo;
  147.     char fState;
  148.     
  149.     void ITextensionCommand(CTextension* textension, short theCmd);
  150.     
  151.     //userAction has the same meaning as the value returned from CTextension::DisplayChanged
  152.     virtual OSErr DoIt(short* userAction) = 0;
  153.     virtual OSErr UndoIt(short* userAction) = 0;
  154.     virtual OSErr RedoIt(short* userAction) = 0;
  155.  
  156. private:
  157. //------
  158. };
  159. //**************************************************************************************************
  160.  
  161. class CTextensionEditCommand : public CTextensionCommand {
  162. public:
  163. //-----
  164.     CTextensionEditCommand();
  165.     
  166.     OSErr ITextensionEditCommand(CTextension* textension, short theCmd
  167.                                                                 , Boolean* noMemForUndo
  168.                                                                 , const TAttrObjModifier* modifier =nil);
  169.     /*modifier->fObj if not nil should be valid during the life of this object and will be deleted when the command is freed.
  170.     Even if an error occur Free should be called.*/
  171.     
  172.     //•overide
  173.     virtual void Free();
  174.  
  175. protected:
  176. //--------
  177.     TAttrObjModifier fAttrObjModifier;
  178.     
  179.     TOffsetRange fOldSelRange;
  180.     
  181.     #ifdef txtnRulers
  182.     TOffsetRange fRulersRange;
  183.     #endif
  184.     
  185.     TOffset fNewSelEnd;
  186.     
  187.     CTextensionIOSuite* fOldIOSuite;
  188.     char fNoOldIOSuiteData; //used to distinguish between fOldIOSuite is nil beacuse of memory error or because old sel range was empty
  189.     
  190.     CTextensionIOSuite* fNewIOSuite; //used for Redo paste
  191.     
  192.     #ifdef txtnNever
  193.     long fCmdContextId;
  194.     #endif
  195.     
  196.     //•overide
  197.     virtual OSErr DoIt(short* userAction);
  198.     virtual OSErr UndoIt(short* userAction);
  199.     virtual OSErr RedoIt(short* userAction);
  200.  
  201.     //•own
  202.     virtual OSErr SaveOldSelRangeIOSuite();
  203.     OSErr SaveNewSelRangeIOSuite();
  204.  
  205.     virtual void GetUndoSelectionRange(TOffsetRange* selRange);
  206.     virtual void GetRedoSelectionRange(TOffsetRange* selRange);
  207.  
  208. private:
  209. //------
  210.     CTextensionIOSuite* SaveIOSuite(TOffsetRange* range, TIOFlags flags);
  211.     
  212.     #ifdef txtnAdvRulers
  213.     void ModifyTab();
  214.     #endif
  215. };
  216. //*************************************************************************************************
  217.  
  218.  
  219. class CTextensionKeyCommand : public CTextensionEditCommand {
  220. public:
  221. //-----
  222.     CTextensionKeyCommand();
  223.     
  224.     OSErr ITextensionKeyCommand(CTextension* textension, TKeyDownParams* keyParams, Boolean* noMemForUndo);
  225.     
  226.     //•override
  227.     
  228.     //•own
  229.     KeyCommandResult NewKey(EventRecord* event, TKeyDownParams* keyParams);
  230.     
  231. protected:
  232. //--------
  233.     //•override
  234.     virtual OSErr SaveOldSelRangeIOSuite();
  235.     
  236.     virtual OSErr DoIt(short* userAction);
  237.     virtual OSErr UndoIt(short* userAction);
  238.     
  239.     virtual void GetUndoSelectionRange(TOffsetRange* selRange);
  240.     virtual void GetRedoSelectionRange(TOffsetRange* selRange);
  241.     
  242.     //•own
  243.     virtual Boolean AcceptKey(const TKeyDownParams* keyParams);
  244.     virtual Boolean AddKey(EventRecord* event, TKeyDownParams* keyParams);
  245.     
  246. private:
  247. //------
  248. char fFirstKey;
  249. char fCantAcceptOtherKeys;
  250. TOffset fMinBackSpaceOffset;
  251. };
  252. //***************************************************************************************************
  253.  
  254. class CTSMTextensionKeyCommand : public CTextensionKeyCommand {
  255. public:
  256. //-----
  257.     CTSMTextensionKeyCommand();
  258.     
  259.     OSErr ITSMTextensionKeyCommand(CTextension* textension, TKeyDownParams* keyParams, Boolean* noMemForUndo);
  260.     
  261.     //•override
  262.  
  263.     //•own
  264.     
  265. protected:
  266. //--------
  267.     //•override
  268.     virtual Boolean AcceptKey(const TKeyDownParams* keyParams);
  269.     virtual Boolean AddKey(EventRecord* event, TKeyDownParams* keyParams);
  270.  
  271.     virtual OSErr UndoIt(short* userAction);
  272.     
  273. private:
  274. //------
  275. CTSMTextension* fTSMTextension;
  276. long fInlineAreaStart;
  277. long fOldCountChars;
  278.  
  279.     void TerminateInline();
  280. };
  281. //***************************************************************************************************
  282.  
  283.  
  284. #endif
  285.